<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户名称" prop="customerID" class="custom-form-item">
        <el-input
            v-model="queryParams.customerID"
            placeholder="请输入用户id"
            clearable
            @keyup.enter="handleQuery"
            class="custom-input"

        />
      </el-form-item>
      <el-form-item label="订单日期" prop="orderDate" class="custom-form-item">
        <el-date-picker clearable
                        v-model="queryParams.orderDate"
                        type="date"
                        value-format="YYYY-MM-DD"
                        placeholder="请选择订单日期"
                        class="custom-date-picker"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus" class="custom-form-item">
        <el-select
            v-model="queryParams.orderStatus"
            placeholder="请选择订单状态"
            clearable
            style="width: 150px; height: 32px; font-size: 14px; line-height: 32px; padding: 0 10px;">
          <el-option
              v-for="dict in order_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付状态" prop="paymentStatus" class="custom-form-item">
        <el-select v-model="queryParams.paymentStatus" placeholder="请选择支付状态" clearable
                   style="width: 150px; height: 32px; font-size: 14px; line-height: 32px; padding: 0 10px;">
          <el-option
              v-for="dict in pay_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="paymentMethod" class="custom-form-item">
        <el-select v-model="queryParams.paymentMethod" placeholder="请选择支付方式" clearable
                   style="width: 150px; height: 32px; font-size: 14px; line-height: 32px; padding: 0 10px;">
          <el-option
              v-for="dict in pay_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="价格" prop="discountAmount" class="custom-form-item">
        <el-input
            v-model="queryParams.discountAmount"
            placeholder="请输入价格"
            clearable
            @keyup.enter="handleQuery"
            class="custom-input"
        />
      </el-form-item>
      <el-form-item label="重金额" prop="totalAmount" class="custom-form-item">
        <el-input
            v-model="queryParams.totalAmount"
            placeholder="请输入重金额"
            clearable
            @keyup.enter="handleQuery"
            class="custom-input"
        />
      </el-form-item>

      <el-form-item label="运费" prop="shippingFee" class="custom-form-item">
        <el-input
            v-model="queryParams.shippingFee"
            placeholder="请输入运费"
            clearable
            @keyup.enter="handleQuery"
            class="custom-input"
        />
      </el-form-item>
      <el-form-item label="收货地址" prop="shippingAddress" class="custom-form-item">
        <el-input
            v-model="queryParams.shippingAddress"
            placeholder="请输入收货地址"
            clearable
            @keyup.enter="handleQuery"
            class="custom-input"
        />
      </el-form-item>
      <el-form-item label="运输方式" prop="shippingMethod" class="custom-form-item">
        <el-input
            v-model="queryParams.shippingMethod"
            placeholder="请输入运输方式"
            clearable
            @keyup.enter="handleQuery"
            class="custom-input"
        />
      </el-form-item>
      <el-form-item  prop="estimatedDeliveryDate" class="custom-form-item">
        <label class="el-form-item__label" style="width: 100px;">预计到达时间</label>
        <el-date-picker clearable
                        v-model="queryParams.estimatedDeliveryDate"
                        type="date"
                        value-format="YYYY-MM-DD"
                        placeholder="请选择预计到达时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item  prop="actualDeliveryDate" class="custom-form-item">
        <label class="el-form-item__label" style="width: 100px;">实际收货时间</label>
        <el-date-picker
            clearable
            v-model="queryParams.actualDeliveryDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择实际收货时间"
        </el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['order:SysOrder:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['order:SysOrder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['order:SysOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['order:SysOrder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
        ref="tableRef"
        row-key="orderID"
        v-loading="loading" :data="SysOrderList"
        @select="selectSingleLine"
        @select-all="handleAllSelection"
        :current-page="queryParams.pageNum"
        :page-size="queryParams.pageSize"
        @current-change="handlePageChange"
    >
      <el-table-column type="selection" width="55" align="center" :reserve-selection="true"  />
      <el-table-column label="订单id" align="center" prop="orderID" />
      <el-table-column label="用户id" align="center" prop="customerID" />
      <el-table-column label="订单日期" align="center" prop="orderDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="orderStatus">
        <template #default="scope">
          <dict-tag :options="order_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="支付状态" align="center" prop="paymentStatus">
        <template #default="scope">
          <dict-tag :options="pay_status" :value="scope.row.paymentStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="paymentMethod">
        <template #default="scope">
          <dict-tag :options="pay_type" :value="scope.row.paymentMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="价格" align="center" prop="discountAmount" />
      <el-table-column label="重金额" align="center" prop="totalAmount" />
      <el-table-column label="数量" align="center" prop="taxAmount" />
      <el-table-column label="运费" align="center" prop="shippingFee" />
      <el-table-column label="收货地址" align="center" prop="shippingAddress" />
      <el-table-column label="运输方式" align="center" prop="shippingMethod" />
      <el-table-column label="预计到达时间" align="center" prop="estimatedDeliveryDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.estimatedDeliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际收货时间" align="center" prop="actualDeliveryDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.actualDeliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数量" align="center" prop="trackingNumber" />
      <el-table-column label="收货状态" align="center" prop="shippingStatus" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['order:SysOrder:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['order:SysOrder:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-checkbox style="margin-left:10px" v-model="data.selected" @click="checkAll()">全部选择</el-checkbox>
    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改业务订单对话框 -->
    <el-dialog :title="title" v-model="open" width="80%" append-to-body
               @close="handleDialogClose"
    >
      <el-form ref="SysOrderRef" :model="form" :rules="rules" label-width="120px">
        <!-- 用户信息 -->
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="用户id" prop="customerID">
              <el-input v-model="form.customerID" placeholder="请输入用户id" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单日期" prop="orderDate">
              <el-date-picker clearable
                              v-model="form.orderDate"
                              type="date"
                              value-format="YYYY-MM-DD"
                              placeholder="请选择订单日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单状态" prop="orderStatus">
              <el-radio-group v-model="form.orderStatus">
                <el-radio v-for="dict in order_status" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 支付信息 -->
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="支付状态" prop="paymentStatus">
              <el-radio-group v-model="form.paymentStatus">
                <el-radio v-for="dict in pay_status" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="支付方式" prop="paymentMethod">
              <el-select v-model="form.paymentMethod" placeholder="请选择支付方式">
                <el-option v-for="dict in pay_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="价格" prop="discountAmount">
              <el-input v-model="form.discountAmount" placeholder="请输入价格" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 其他信息 -->
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="重金额" prop="totalAmount">
              <el-input v-model="form.totalAmount" placeholder="请输入重金额" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="数量" prop="taxAmount">
              <el-input v-model="form.taxAmount" placeholder="请输入数量" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="运费" prop="shippingFee">
              <el-input v-model="form.shippingFee" placeholder="请输入运费" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 地址和运输方式 -->
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="收货地址" prop="shippingAddress">
              <el-input v-model="form.shippingAddress" placeholder="请输入收货地址" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="运输方式" prop="shippingMethod">
              <el-input v-model="form.shippingMethod" placeholder="请输入运输方式" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 时间相关 -->
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="预计到达时间" prop="estimatedDeliveryDate">
              <el-date-picker clearable
                              v-model="form.estimatedDeliveryDate"
                              type="date"
                              value-format="YYYY-MM-DD"
                              placeholder="请选择预计到达时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="实际收货时间" prop="actualDeliveryDate">
              <el-date-picker clearable
                              v-model="form.actualDeliveryDate"
                              type="date"
                              value-format="YYYY-MM-DD"
                              placeholder="请选择实际收货时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <AvatarUploader></AvatarUploader>
          </el-col>

        </el-row>
      </el-form>
      <span class="alert-text">当前勾选人数:{{
          data.dataSelectList.length ? data.dataSelectList.length - data.newOrderForm.removeSelectData.length : 0 }}</span>

      <el-table
          ref="newAddtableRef"
          row-key="orderID"
          v-loading="loading" :data="data.newOrderForm.tableList"
          @select="selectOwerSingleLine"
          @select-all="handleOwerAllSelection"
      >
        <el-table-column type="selection" width="55" align="center" :reserve-selection="true"  />
        <el-table-column label="订单id" align="center" prop="orderID" />
        <el-table-column label="用户id" align="center" prop="customerID" />
        <el-table-column label="订单日期" align="center" prop="orderDate" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单状态" align="center" prop="orderStatus">
          <template #default="scope">
            <dict-tag :options="order_status" :value="scope.row.orderStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="支付状态" align="center" prop="paymentStatus">
          <template #default="scope">
            <dict-tag :options="pay_status" :value="scope.row.paymentStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="支付方式" align="center" prop="paymentMethod">
          <template #default="scope">
            <dict-tag :options="pay_type" :value="scope.row.paymentMethod"/>
          </template>
        </el-table-column>
        <el-table-column label="价格" align="center" prop="discountAmount" />
        <el-table-column label="重金额" align="center" prop="totalAmount" />
        <el-table-column label="数量" align="center" prop="taxAmount" />
        <el-table-column label="运费" align="center" prop="shippingFee" />
        <el-table-column label="收货地址" align="center" prop="shippingAddress" />
        <el-table-column label="运输方式" align="center" prop="shippingMethod" />
        <el-table-column label="预计到达时间" align="center" prop="estimatedDeliveryDate" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.estimatedDeliveryDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实际收货时间" align="center" prop="actualDeliveryDate" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.actualDeliveryDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center" prop="trackingNumber" />
        <el-table-column label="收货状态" align="center" prop="shippingStatus" />
        <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination
          v-show="data.newOrderForm.total>0"
          :total="data.newOrderForm.total"
          v-model:page="data.newOrderForm.pageNum"
          v-model:limit="data.newOrderForm.pageSize"
          @pagination="getNewList"
      />

      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="SysOrder">
import { listSysOrder, getSysOrder, delSysOrder, addSysOrder, updateSysOrder }
from "@/api/sysOrder/sysOrder";
import {onMounted}  from "vue";
import AvatarUploader from '@/views/components/avatarUploader';
const { proxy } = getCurrentInstance();

const { pay_status, pay_type, order_status } = proxy.useDict('pay_status', 'pay_type', 'order_status');

const SysOrderList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    customerID: null,
    orderDate: null,
    orderStatus: null,
    paymentStatus: null,
    paymentMethod: null,
    discountAmount: null,
    totalAmount: null,
    taxAmount: null,
    shippingFee: null,
    shippingAddress: null,
    shippingMethod: null,
    estimatedDeliveryDate: null,
    actualDeliveryDate: null,
    trackingNumber: null,
    shippingStatus: null,
    updateTime: null,
    createTime: null
  },
  rules: {
    customerID: [
      { required: true, message: "用户id不能为空", trigger: "blur" }
    ],
    orderDate: [
      { required: true, message: "订单日期不能为空", trigger: "blur" }
    ],
    orderStatus: [
      { required: true, message: "订单状态不能为空", trigger: "change" }
    ],
    paymentStatus: [
      { required: true, message: "支付状态不能为空", trigger: "change" }
    ],
    paymentMethod: [
      { required: true, message: "支付方式不能为空", trigger: "change" }
    ],
    discountAmount: [
      { required: true, message: "价格不能为空", trigger: "blur" }
    ],
    totalAmount: [
      { required: true, message: "重金额不能为空", trigger: "blur" }
    ],
    shippingAddress: [
      { required: true, message: "收货地址不能为空", trigger: "blur" }
    ],
  },

      selected:false,
  dataSelectList:[],
  changeBz:0,
  newOrderForm: {
    pageNum: 1,
    pageSize: 10,
    tableList:[],
    removeSelectData:[],
    inserDateItem:[]
  }


}

);
const tableRef =ref(null);
const newAddtableRef =ref(null);

const { queryParams, form, rules } = toRefs(data);

/** 查询业务订单列表 */
function getList() {
  loading.value = true;
  listSysOrder(queryParams.value).then(response => {
    SysOrderList.value = response.rows;
    total.value = response.total;
    loading.value = false;
    checkBoxState(response.rows,tableRef)
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    orderID: null,
    customerID: null,
    orderDate: null,
    orderStatus: null,
    paymentStatus: null,
    paymentMethod: null,
    discountAmount: null,
    totalAmount: null,
    taxAmount: null,
    shippingFee: null,
    shippingAddress: null,
    shippingMethod: null,
    estimatedDeliveryDate: null,
    actualDeliveryDate: null,
    trackingNumber: null,
    shippingStatus: null,
    updateTime: null,
    createTime: null
  };
  proxy.resetForm("SysOrderRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.orderID);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  nextTick(()=>{
    getNewList();
  })
  title.value = "添加业务订单";
}

function getNewList(){
  loading.value = true;
  data.newOrderForm.total = data.dataSelectList.length;
  let currentIndex = (data.newOrderForm.pageNum-1)*data.newOrderForm.pageSize;
  data.newOrderForm.tableList = data.dataSelectList.slice(currentIndex,currentIndex+data.newOrderForm.pageSize);
  checkOwerBoxState(data.newOrderForm.tableList,data.dataSelectList,data.newOrderForm.removeSelectData,newAddtableRef)
  loading.value = false;

}

function checkOwerBoxState(rows,selectedData,deleteData,tabRef){
  tabRef.value.clearSelection();
  rows.forEach(row => {
    const tableRow = selectedData.find(item => item.orderID == row.orderID);
    const removeRow = deleteData.find(item => item.orderID == row.orderID);
    if (tableRow) {
      tabRef.value.toggleRowSelection(tableRow, true);
    }
    if (removeRow) {
      tabRef.value.toggleRowSelection(removeRow, false);
    }
  });
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _orderID = row.orderID || ids.value
  getSysOrder(_orderID).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改业务订单";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["SysOrderRef"].validate(valid => {
    if (valid) {
      setParam();
      if (form.value.orderID != null) {
        updateSysOrder(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addSysOrder(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

function setParam(){
let temp = data.dataSelectList
  if (data.newOrderForm.removeSelectData.length > 0) {
    temp = data.dataSelectList.filter(item =>
        !data.newOrderForm.removeSelectData.includes(item)
    );
  }
  data.newOrderForm.inserDateItem=temp;
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _orderIDs = row.orderID || ids.value;
  proxy.$modal.confirm('是否确认删除业务订单编号为"' + _orderIDs + '"的数据项？').then(function() {
    return delSysOrder(_orderIDs);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('order/SysOrder/export', {
    ...queryParams.value
  }, `SysOrder_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  getList()
});


/**
 * 全部选中逻辑
 */

function checkAll(){
if(!data.selected){
  const copiedParams = { ...queryParams.value, pageNum:1,pageSize: 1000 };
  loading.value = true;
  listSysOrder(copiedParams).then(response => {
    data.dataSelectList =  response.rows;
    data.pageNum = 1;
    tableRef.value.clearSelection();
    tableRef.value.toggleAllSelection();
    loading.value = false;
  });
}else{
  tableRef.value.clearSelection();
  data.dataSelectList =[];
  data.newOrderForm.total =0;
}
}


function checkBoxState(rows,obj){
  obj.value.clearSelection();
      rows.forEach(row => {
      const tableRow = data.dataSelectList.find(item => item.orderID === row.orderID);
      if (tableRow) {
        tableRef.value.toggleRowSelection(tableRow, true);
      }
    });

}

function selectSingleLine(section, row) {
  let fitemIndex = data.dataSelectList.findIndex((item) => {
    return item.orderID == row.orderID;
  });
  if (fitemIndex < 0) {
    data.dataSelectList.push(row);
  } else {
    data.dataSelectList.splice(fitemIndex, 1);
  }
}

function handleAllSelection(val) {
  let selectData = [...new Set(val)]; // 确保 selectData 中的数据唯一
  if (selectData.length == 0) {
    SysOrderList.value.forEach(row => {
      // 查找匹配的项，获取索引
      let tempIndex = data.dataSelectList.findIndex(item => item.orderID == row.orderID);
      if (tempIndex >= 0) {
        // 删除该项
        data.dataSelectList.splice(tempIndex, 1);
      }
    });
  } else {
    SysOrderList.value.forEach(row => {
      // 查找是否已经存在该项
      let temp = data.dataSelectList.find(item => item.orderID == row.orderID);
      if (!temp) {
        // 如果不存在，则添加到 dataSelectList
        data.dataSelectList.push(row);
      }
    });
  }
}

//弹框全选
function selectOwerSingleLine(section, row){

  let fitemIndex = data.newOrderForm.removeSelectData.findIndex((item) => {
    return item.orderID == row.orderID;
  });
  if (fitemIndex < 0) {
    data.newOrderForm.removeSelectData.push(row);
  } else {
    data.newOrderForm.removeSelectData.splice(fitemIndex, 1);
  }
}

function handleOwerAllSelection(val) {
  let selectData = [...new Set(val)]; // 确保 selectData 中的数据唯一
  if (selectData.length === 0) {
    data.newOrderForm.tableList.forEach(row => {
      // 查找匹配的项，获取索引
      let tempIndex = data.newOrderForm.removeSelectData.findIndex(item => item.orderID == row.orderID);
      if (tempIndex <= 0) {
        // 删除该项
        data.newOrderForm.removeSelectData.push(row);
      }
    });
  } else {
    data.newOrderForm.tableList.forEach(row => {
      // 查找是否已经存在该项
      let temp = data.newOrderForm.removeSelectData.find(item => item.orderID == row.orderID);
      if (temp) {
        // 如果不存在，则添加到 dataSelectList
        data.newOrderForm.removeSelectData.splice(row,1)
      }
    });
  }
}

function  handleDialogClose(){
  data.newOrderForm.removeSelectData=[]
}

</script>

<style >


/* 自定义 el-form-item 样式 */
.custom-form-item .el-form-item__label {
  font-size: 10px !important;  /* 修改标签文字大小 */
}

/* 自定义 el-input 样式 */
.custom-input .el-input__inner {
  font-size: 8px !important;  /* 修改输入框文字大小 */
  height: 26px !important;     /* 修改输入框高度 */
  width:80px !important;
}



</style>

<style scoped>
.custom-form-item {
  margin-bottom: 15px; /* 为表单项添加底部间距 */
}
.el-select {
  width: 100%; /* 让选择框的宽度自适应父容器 */
  font-size: 12px; /* 设置字体大小 */
}
.el-option {
  font-size: 14px; /* 设置下拉选项的字体大小 */
}


</style>

